package com.weixin.controller;


import com.github.pagehelper.PageHelper;
import com.weixin.entity.User;
import com.weixin.service.IUserService;
import com.weixin.uitl.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gpf
 * @since 2018-12-16
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping("/list")
    public R listAll(@RequestParam(value = "pageNumber",defaultValue = "1")Integer pageNumber, @RequestParam(value = "pageSize",defaultValue = "3")Integer pagesize){
        /**
         * 查询所有
         */
        PageHelper.startPage(pageNumber,pagesize );
        List<User> userList = userService.list();
        /**
         * 查询总条目
         */
        int total = userService.count();
        return R.ok().put("total",total).put("rows",userList);

    }

    @PostMapping("/remove/{id}")
    public R removeById(@PathVariable Integer id){
        boolean b = userService.removeById(id);
        System.out.println(id);
        if(b){
            return R.ok("删除成功");
        }else {
            return R.error("删除失败");
        }

    }
}
